//
//  YJBResetPasswordViewController.m
//  YunJiaBaoFirst
//
//  Created by 腾云小白龍 on 16/7/27.
//  Copyright © 2016年 腾云小白龍. All rights reserved.
//

#import "YJBResetPasswordViewController.h"

@interface YJBResetPasswordViewController ()
@property (nonatomic, strong) UITextField *NewPWTextField;
@property (nonatomic, strong) UITextField *sureNewPWTextField;
@end

@implementation YJBResetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setNavigationItemWithTitle:@"设置新密码"];
    [self initSubViews];
}


-(void)initSubViews{
    UIScrollView *mainScrollView = [[UIScrollView alloc]initWithFrame:KMainScreen.bounds];
    mainScrollView.scrollEnabled = YES;
    mainScrollView.showsVerticalScrollIndicator = NO;
    mainScrollView.showsHorizontalScrollIndicator = NO;
    mainScrollView.contentSize = CGSizeMake(KMainScreenSize.width, KMainScreenSize.height+1);
    [self.view addSubview:mainScrollView];
    
    CGFloat scaleH = KMainScreenSize.height/667;
    CGFloat fontSize = 16;
    if (KMainScreenSize.height == 480) {
        fontSize = 13;
    }
    UILabel *cueLabel = ({
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, KMainScreenSize.width,scaleH* 44)];
        label.textAlignment = NSTextAlignmentLeft;
        label.text = @"新密码:";
        label.font = [UIFont systemFontOfSize:fontSize];
        label.textColor = [UIColor blackColor];
        label;
    });
    [mainScrollView addSubview:cueLabel];
    
    UIView *contentView = ({
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(cueLabel.frame),KMainScreenSize.width,scaleH* 44)];
        view.backgroundColor = [UIColor whiteColor];
        view;
    });
    [mainScrollView addSubview:contentView];
    
    self.NewPWTextField = ({
        UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(15,0,KMainScreenSize.width - 15 - scaleH*90,scaleH* 44)];
        textField.placeholder = @"请输入新密码";
        textField.textAlignment = NSTextAlignmentLeft;
        textField.font = [UIFont systemFontOfSize:fontSize];
        textField.keyboardType = UIKeyboardTypePhonePad;
        textField.secureTextEntry = YES;
        [contentView addSubview:textField];
        textField;
    });
    
    UILabel *sureCueLabel = ({
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15,CGRectGetMaxY(contentView.frame), KMainScreenSize.width,scaleH* 44)];
        label.textAlignment = NSTextAlignmentLeft;
        label.text = @"确认新密码:";
        label.font = [UIFont systemFontOfSize:fontSize];
        label.textColor = [UIColor blackColor];
        label;
    });
    [mainScrollView addSubview:sureCueLabel];
    
    UIView *surreContentView = ({
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(sureCueLabel.frame),KMainScreenSize.width,scaleH* 44)];
        view.backgroundColor = [UIColor whiteColor];
        view;
    });
    [mainScrollView addSubview:surreContentView];
    
    self.sureNewPWTextField = ({
        UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(15,0,KMainScreenSize.width - 15 -scaleH* 90,scaleH* 44)];
        textField.placeholder = @"请再次输入新密码";
        textField.textAlignment = NSTextAlignmentLeft;
        textField.font = [UIFont systemFontOfSize:fontSize];
        textField.keyboardType = UIKeyboardTypePhonePad;
        textField.secureTextEntry = YES;
        [surreContentView addSubview:textField];
        textField;
    });
    
    UIButton*sureBtn = ({
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(surreContentView.frame) +scaleH* 40, KMainScreenSize.width - 30,scaleH* 40)];
        [button setTitle:@"确认" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        button.layer.cornerRadius = 5;
        button.layer.masksToBounds = YES;
        button.titleLabel.font = [UIFont systemFontOfSize:fontSize];
        button.backgroundColor = KMainColor;
        button;
    });
    [sureBtn addTarget:self action:@selector(sureBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [mainScrollView addSubview:sureBtn];
    
}

-(void)sureBtnClick{
    if (!self.NewPWTextField.text.length) {
            [SVProgressHUD showImage:nil status:@"请输入新密码"];
            [self performSelector:@selector(SVProgressHUDdismiss) withObject:nil afterDelay:1.0f];
            return;
    
        }
    
    if (!self.sureNewPWTextField.text.length) {
            [SVProgressHUD showImage:nil status:@"请再次输入新密码"];
            [self performSelector:@selector(SVProgressHUDdismiss) withObject:nil afterDelay:1.0f];
            return;
            
        }
    
    if (![self.NewPWTextField.text isEqualToString:self.sureNewPWTextField.text]) {
        [SVProgressHUD showErrorWithStatus:@"您两次输入的密码不相同,请重新输入"];
        [self performSelector:@selector(SVProgressHUDdismiss) withObject:nil afterDelay:1.5f];
        return;
    }
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
